//点击一次隐藏，再点击一次显示
$('.menu').on('click', 'a:nth-child(8)', function() {
        //console.log(123);
        $('.menu a:nth-child(n+9)').fadeToggle(500);
    })
    //登录页面
$('.login').on('click', function() {
        // console.log(123)
        location.href = './views/login.html';
    })
    //注册页面
$('.register').on('click', function() {
    location.href = './views/register.html';
})



$(function() {
    //获取菜单数据
    $.ajax({
            url: "http://193.112.55.79:9090/api/getindexmenu",
            type: "get",
            dataType: "json",
            success: function(res) {
                // console.log(res);
                var htmlStr = template("menuTmp", res);
                $(".menu").html(htmlStr);
            }
        })
        // 获取超级折扣推荐数据
    $.ajax({
        type: "get",
        url: "http://193.112.55.79:9090/api/getmoneyctrl",
        dataType: "json",
        success: function(res) {
            //console.log(res.result);
            var htmlStr1 = template("discountTmp", res);
            //console.log(htmlStr1);
            $(".count .content").html(htmlStr1);

            // 修改折扣部分评论数
            var counts = document.querySelectorAll('.productComCount');
            // console.log(counts);
            for (var i = 1; i < counts.length; i++) {
                var text = counts[i].dataset.count;
                // console.log(text);
                var num = text.replace(/[^0-9]/ig, "");
                //    console.log(num);
                counts[i].innerText = num;
            }

        }
    })


    //返回顶部
    $('.footer_top .back').on('click', function() {
        var timeId = setInterval(function() {
            var target = 0;
            var leader = scroll().scrollTop;
            leader = leader + (target - leader) / 10;
            scrollTo(0, leader);
            if (leader == target) {
                clearInterval(timeId);
            }
        })
    })

    function scroll() {
        return {
            scrollTop: window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop || 0,
            scrollLeft: window.pageXOffset || document.documentElement.scrollLeft || document.body.scrollLeft || 0,
        }
    }
})